package FailedStudent;

import java.io.*;
import java.util.Arrays;
import java.util.HashSet;

/**
 * @Auther:SunPeng
 * @Date:2020/7/29-07-29
 * @Description:FailedStudent
 * @version:1.0
 */
public class FailedStudent {

    public static void main(String[] args) {
        try{
            BufferedReader br = new BufferedReader( new FileReader("D:\\JavaTest\\Student3.txt"));
            BufferedWriter bw = new BufferedWriter( new FileWriter("D:\\JavaTest\\FailedStudent.txt"));

            //读入
            HashSet<Student> hs = new HashSet<Student>();
            String str = null;
            while ((str = br.readLine()) != null){
                String[] strs = str.split(",");
                hs.add(new Student(strs));
            }

            //筛选
            for(Student s:hs){
                if(s.getScore()<60){
                    System.out.println(s.toString());
                    bw.write(s.toString());
                    bw.newLine();
                }
            }
            bw.flush();

        }catch (FileNotFoundException e1){
            System.out.println("读异常");
            System.exit(-1);
        }catch(IOException e){
            System.out.println("IO异常");
            System.exit(-1);
        }
    }
}


class Student{
    private int id = 0;
    private String name = null;
    private int score = 0;

    public Student() {
    }

    public Student(String[] strs) {
        this.id = Integer.valueOf(strs[0]);
        this.name = strs[1];
        this.score = Integer.valueOf(strs[2]);
    }

    @Override
    public String toString() {
        return id + "," + name + "," + score;
    }

    public int getScore() {
        return score;
    }

}
